package model;

import java.awt.Point;

import model.MatriceCreuseOBSOLETE.Line;

public class PointControl extends Point {

	private static final long serialVersionUID = 1L;
	public static final int rayon = 10;
	private PointControl next;
	private PointControl previous;
	private Line ligne;

	private PointControl thisPoint;
	private Courbe courbes;
	private Point tangente;
	
	/**
	 * Constructeur par copie depuis un point
	 * @param addedPoint
	 */
	public PointControl(Point addedPoint, Courbe courbe) {
		super(addedPoint);
		this.courbes = courbe;
		tangente = new Point(0,0);
	}

	public Courbe getCourbes() {
		return courbes;
	}

	public void setCourbes(Courbe courbes) {
		this.courbes = courbes;
	}

	public PointControl getThisPoint() {
		if (thisPoint != null)
			return thisPoint;
		else return this;
	}

	private void setThisPoint(PointControl thisPoint) {
		this.thisPoint = thisPoint;
	}

	public Line getLigne() {
		return ligne;
	}

	public void setLigne(Line ligne) {
		this.ligne = ligne;
	}

	public PointControl getNextX() {
		return next;
	}

	public void setNext(PointControl nextX) {
		this.next = nextX;
	}

	public PointControl getPreviousX() {
		return previous;
	}

	public void setPrevious(PointControl previousX) {
		this.previous = previousX;
	}

	public void insertPoint(PointControl point) {
		PointControl suivant = this.next;
		if (suivant != null)
			suivant.setPrevious(point);
		point.setNext(suivant);

		this.setNext(point);
		point.setPrevious(this);
		
		this.setThisPoint(this);
	}

	public void removeMe() {
		PointControl suivant = this.next;
		PointControl precedent = this.previous;
		if (suivant == null && precedent == null) {
			this.getLigne().removeMe();
			this.setThisPoint(null);
		}
		if (suivant != null) {
			suivant.setPrevious(precedent);
			this.setThisPoint(precedent);
		}
		if (precedent != null) {
			precedent.setNext(suivant);
			this.setThisPoint(suivant);
		}

	}

	public void insertPointBefore(PointControl newPointControl) {
		// TODO Auto-generated method stub
		
	}

	public double getCtrlY() {
		return tangente.getY();
	}

	public double getCtrlX() {
		return tangente.getX();
	}

	public void setTangente(Point p) {
		//tangente.setLocation(p.getX() - this.getX(), p.getY() - this.getY());
		tangente.setLocation(this.getX() - p.getX() , this.getY() - p.getY());
	}
}
